<%@ page language="java" import="java.util.*,com.dao.*,com.common.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%String path = request.getContextPath();String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+ path + "/";%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="css/maintable.css"></link>
<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<script type="text/javascript">
$(function(){
	$("#ch_checkall,#top_ch_checkall").click(function(){
		if(this.checked){
			$("input[name=ck_id]").attr("checked","checked");
		}else{
			$("input[name=ck_id]").removeAttr("checked");
		}		
	});
	
	$("table tr").mouseover(function(){
		$(this).css("background","#D3EAEF");
		$(this).siblings().css("background","white");
	});
	
});
</script>					


<script>

function subForm(pageIndex)
{
	document.form1.submit();
    window.location.href="OrderServlet.do?flag=manage&pageIndex="+pageIndex;
}
 
function validate(){
	var index=document.getElementById("pageIndex").value;
	if(index>=1&&index<=${pageInfo.pageCount}){  
		window.location.href="OrderServlet.do?flag=manage&pageIndex="+document.getElementById("pageIndex").value;
	}else{ 
		alert("跳转页码输入有误");
	}
	
}

//点击上方的删除按钮,进行多项删除
function delMuti(){
	//判断用户至少选了一项
	if($("input[name=ck_id]:checked").size()==0){
		alert("请至少选一项!");
	}
	else{
		if(confirm('确定要删除所选项吗')){
			$("#flag_id").val("delOrders");
			form1.submit();
		}
	}
}

</script>

</head>

<body>

	 <%
 		request.setAttribute("orderStateList",Constant.EnumOrderState.values());
	 %>
			
		
	<div class="div_title">
		<div class="div_titlename">
			<img src="images/san_jiao.gif"><span>订单管理|订单维护</span>
		</div>
		<div class="div_titleoper">
			<input type="checkbox" id="top_ch_checkall" /> 全选
			<a href="javascript:delMuti()">
			<img src="images/del.gif" />删除</a>
		</div>
		
	</div>
	
	<form action="OrderServlet.do" name="order_manageForm" >
		<input type="hidden" name="flag" value="manage" />
		
		<div class="div_selected">
			
			订单号：<input id="orderNo" name="orderNo" value="${param.orderNo}"> 
			下单日期：从<input type="date" id="startDate" name="startDate" value="${param.startDate}">到
					<input type="date" id="endDate" name="endDate" value="${param.endDate}">
			订单状态：<select name="orderState">
						<option value="">全部</option>
						<c:forEach var="state" items="${orderStateList}">
							<c:if test="${state==param.orderState }">
								<option value="${state}" selected="selected">${state}</option>
							</c:if>
							<c:if test="${state!=param.orderState }">
								<option value="${state}" >${state}</option>
							</c:if>
						</c:forEach>
					</select> 
			 <input type="submit" value="查询"  > 
			 
		</div>
		
		<table class="main_table">
			
			<tr>
				<th><input type="checkbox" id="ch_checkall" /></th>
				<th>订单号</th>
				<th>付款方式</th>
				<th>订单金额</th>
				<th>订单状态</th>
				<th>邮寄方式</th>
				<th>生成日期</th>
				<th>发货地址</th>
				<th>操作</th>
			</tr>
			<c:forEach var="order" items="${orderList}">
				<tr>
					<td>
						<input type="checkbox" name="ck_id" value="${order.id}" />
					</td>
					<td>${order.orderNo}</td>
					<td>${order.payMethod}</td>
					<td>${order.amount}</td>
					<td>${order.orderState}</td>
					<td>${order.postMethod}</td>
					<td>${order.orderDate}</td>
					<td>${order.address}</td>
					<td>
						<a href="OrderServlet.do?flag=orderview&id=${order.id}">查看</a>| 
						<c:if test="${order.orderState=='已支付'}">
							<a href="OrderServlet.do?flag=orderPost&id=${order.id}&pageIndex=${pageInfo.pageIndex }" onclick="return confirm('确认发货？')">发货</a>
						</c:if>
						<c:if test="${order.orderState=='未支付'}">
							<a href="OrderServlet.do?flag=del&id=${order.id}" onclick="return confirm('确认删除？')">删除</a>
						</c:if>
					</td>
				</tr>
			</c:forEach>
		</table>
	</form>

	<div class="div_page">
		<div class="div_page_left">
			共有 <label>${pageInfo.rowCount }</label> 条记录，当前第 <label>${pageInfo.pageIndex }</label>
			页，共 <label>${pageInfo.pageCount }</label> 页
		</div>

		<div class="div_page_right">
			<c:choose>
				<c:when test="${pageInfo.hasPre }">
					<button onclick="subForm(1)">首页</button>
					<button onclick="subForm(${pageInfo.pageIndex-1})">上一页</button>
				</c:when>

				<c:otherwise>
								  			 首页
							  	 			 上一页
				</c:otherwise>
			</c:choose>

			<c:choose>
				<c:when test="${pageInfo.hasNext}">
					<button onclick="subForm(${pageInfo.pageIndex+1})">下一页</button>
					<button onclick="subForm(${pageInfo.pageCount})">尾页</button>
				</c:when>

				<c:otherwise>
								  			下一页 
							  	 		         尾页
				</c:otherwise>
			</c:choose>

		<button onclick="validate()">转到</button>  第 <input id="pageIndex" name="pageIndex"  value="${page.pageIndex }"> 页
		</div>

	</div>

	<script type="text/javascript">
		var msg='${msg}';
	 	 if(msg!=''){
	 	 	alert(msg);
	 	 }		  	 
	</script>


</body>

</html>
